﻿<?php
  include('../config.php');
  header('Access-Control-Allow-Origin:*');
  // 接收前端传递过来的用户名和密码
  $username = $_POST['username'];
  $password = $_POST['password'];

  // 根据用户名密码查找数据库里是否存在这条数据
  // php的双引号可以直接解析变量
  $sql = "select * from users where username='$username' and password='$password'";
  

  //echo $sql;

  // 执行sql语句
  // $res 是一个资源类型的数据
  $res = mysql_query($sql);

  // 获取$res的条数
  $num = mysql_num_rows($res);

  if ($num > 0) {
    echo json_encode(array(
      "code" => 200,
      "body" => array(
        "username" => $username,
        "password" => $password
      )
    ));
  } else {
    echo json_encode(array(
      "code" => 201,
      "body" => array(
        "msg" => "用户名或密码错误"
      )
    ));
  }


?>